package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.RptSales;
import com.ruoyi.system.service.IRptSalesService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 销售原始数据Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@Controller
@RequestMapping("/system/sales")
public class RptSalesController extends BaseController
{
    private String prefix = "system/sales";

    @Autowired
    private IRptSalesService rptSalesService;

    @RequiresPermissions("system:sales:view")
    @GetMapping()
    public String sales()
    {
        return prefix + "/sales";
    }

    /**
     * 查询销售原始数据列表
     */
    @RequiresPermissions("system:sales:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RptSales rptSales)
    {
        startPage();
        List<RptSales> list = rptSalesService.selectRptSalesList(rptSales);
        return getDataTable(list);
    }

    /**
     * 导出销售原始数据列表
     */
    @RequiresPermissions("system:sales:export")
    @Log(title = "销售原始数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RptSales rptSales)
    {
        List<RptSales> list = rptSalesService.selectRptSalesList(rptSales);
        ExcelUtil<RptSales> util = new ExcelUtil<RptSales>(RptSales.class);
        return util.exportExcel(list, "销售原始数据数据");
    }

    /**
     * 新增销售原始数据
     */
    @RequiresPermissions("system:sales:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存销售原始数据
     */
    @RequiresPermissions("system:sales:add")
    @Log(title = "销售原始数据", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RptSales rptSales)
    {
        return toAjax(rptSalesService.insertRptSales(rptSales));
    }

    /**
     * 修改销售原始数据
     */
    @RequiresPermissions("system:sales:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RptSales rptSales = rptSalesService.selectRptSalesById(id);
        mmap.put("rptSales", rptSales);
        return prefix + "/edit";
    }

    /**
     * 修改保存销售原始数据
     */
    @RequiresPermissions("system:sales:edit")
    @Log(title = "销售原始数据", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RptSales rptSales)
    {
        return toAjax(rptSalesService.updateRptSales(rptSales));
    }

    /**
     * 删除销售原始数据
     */
    @RequiresPermissions("system:sales:remove")
    @Log(title = "销售原始数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(rptSalesService.deleteRptSalesByIds(ids));
    }
}
